<template>
  <div class="app-container">
    <div>
      <el-menu :default-active="tab" class="el-menu-demo" mode="horizontal" @select="changeTab">
        <el-menu-item index="my">我负责的</el-menu-item>
        <el-menu-item index="all">全部</el-menu-item>
        <el-menu-item index="warehouse">仓库设置</el-menu-item>
      </el-menu>
    </div>
    <!--数据列表-->
    <div v-show="tab != 'warehouse'" class="table-container" style="margin-top:0px">
      <div>
        <!--筛选-->
        <el-radio-group v-model="type" size="small" style="margin-top:10px;" @change="changeType">
          <el-radio-button label="4">定金待审核</el-radio-button>
          <el-radio-button label="1">需安排</el-radio-button>
          <el-radio-button label="2">已安排</el-radio-button>
          <el-radio-button label="3">未安排已发货</el-radio-button>
        </el-radio-group>
      </div>
      <vxe-grid ref='xGrid' v-bind="gridOptions" size="mini" :loading="listLoading" v-if="type == 1 || type == 4" @checkbox-change="checkboxChange">
        <template #form>
            <!--搜索-->
            <div>
              <div style="background: #f5f7fa;padding:15px 15px 0 15px;border:1px solid #EBEEF5;border-bottom:0.5px solid #EBEEF5;">
                <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">

                    <el-form-item label="期望发货时间：">
                    <el-date-picker
                      :clearable="false"
                      :picker-options="pickerOptions2"
                      v-model="listQuery.date"
                      type="daterange"
                      format="yyyy 年 MM 月 dd 日"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
                    </el-date-picker>
                  </el-form-item>

                  <el-form-item label="客户名称：">
                  <el-select
                    clearable
                    v-model="listQuery.customerId"
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="querySearch"
                    style="width: 260px;">
                    <el-option
                      v-for="item in querySearchList"
                      :key="item.customerId"
                      :label="item.customerName"
                      :value="item.customerId">
                    </el-option>
                  </el-select>
                </el-form-item>
                  <el-form-item label="合同号：">
                    <el-input v-model="listQuery.orderSn" clearable></el-input>
                  </el-form-item>
                  <el-form-item label="品名：">
                    <el-select
                      clearable
                      v-model="listQuery.goodsName">
                      <el-option
                        v-for="item in options2"
                        :key="item.goodsName"
                        :label="item.goodsName"
                        :value="item.goodsName">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="牌号：">
                    <el-input v-model="listQuery.goodsKingName" placeholder="请输入牌号" clearable></el-input>
                  </el-form-item>
                  <el-form-item label="业务员：">
                    <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable >
                      <el-option
                        v-for="item in userOptionList"
                        :key="item.userId"
                        :label="item.realName"
                        :value="item.userId">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="发货类型：" >
                    <el-select v-model="listQuery.sendType"  clearable>
                      <el-option value="公司发货">公司发货</el-option>
                      <el-option value="采购发货">采购发货</el-option>
                      <el-option value="客户自提">客户自提</el-option>
                    </el-select>
                  </el-form-item>

                  <el-form-item label="预计发货仓库：">
                    <el-input v-model="listQuery.warehouseName" clearable></el-input>
                  </el-form-item>

                  <el-form-item label="排序：">
                    <el-select v-model="listQuery.orderBy" clearable>
                      <el-option value="goods" label="默认排序"></el-option>
<!--                      <el-option value="financeTime" label="审核时间"></el-option>-->
                      <el-option value="financeTimeDesc" label="财务审核时间降序"></el-option>
                      <el-option value="financeTimeAsc" label="财务审核时间升序"></el-option>
                      <el-option value="sendDateDesc" label="预计发货时间降序"></el-option>
                      <el-option value="sendDateAsc" label="预计发货时间升序"></el-option>
                      <el-option value="expectSendDateDesc" label="期望发货时间降序"></el-option>
                      <el-option value="expectSendDateAsc" label="期望发货时间升序"></el-option>
                      <el-option value="timeSureDateDesc" label="合同约定时间降序"></el-option>
                      <el-option value="timeSureDateAsc" label="合同约定时间升序"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="安排状态：">
                    <el-select  v-model="listQuery.planDeliverState" filterable placeholder="请选择" clearable>
                      <el-option
                        :key="0"
                        label="未安排"
                        :value="0">
                      </el-option>
                      <el-option
                        :key="1"
                        label="部分安排"
                        :value="1">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="合同公司：">
                    <el-input v-model="listQuery.fromCompany" clearable></el-input>
                  </el-form-item>

                  <el-form-item label="过滤标记：">
                    <el-select  v-model="listQuery.tagContent" placeholder="请选择" multiple>
                      <el-option v-for="(item,index) in tagContentList" :key="index" :value="item"></el-option>
                    </el-select>
                  </el-form-item>

                   <el-form-item label="过滤厂家：">
                    <el-select v-model="listQuery.isFilterBrand" placeholder="请选择" clearable>
                      <el-option :value="1" label="是"></el-option>
                      <el-option :value="0" label="否"></el-option>
                    </el-select>
                  </el-form-item>

                  <el-form-item>
                    <el-button @click="handleSearchList" type="primary">查询</el-button>
                    <el-button type="success" size="small" @click="margeph" v-if="type == 1">合并排货</el-button>
                    <el-button type="primary" size="small" @click="pumsph">采购排货</el-button>
                  </el-form-item>
                </el-form>
              </div>
              <div style="padding-top:10px">
                <el-radio-group v-model="listQuery.brandName" size="small" @change="handleSearchList" v-if="type == 1">
                  <el-radio-button label="">全部</el-radio-button>
                  <el-radio-button v-for="item in goodsTabList" :label="item.cddValue" :key="item.cddValue">{{ item.cddValue}}</el-radio-button>
                </el-radio-group>
              </div>

            </div>
        </template>
        <template #pager>
          <div style="overflow: hidden">
            <div style="color:#606266;margin-top:20px;float:left;">未安排总计：<span style="font-weight: bold">{{unPlanNum}}</span></div>
            <div class="pagination-container" style="float:right;">
              <el-pagination
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                layout="total, sizes,prev, pager, next,jumper"
                :current-page.sync="listQuery.pageNum"
                :page-size="listQuery.pageSize"
                :page-sizes="[10,15,20,50,100,200]"
                :total="count">
              </el-pagination>
            </div>
          </div>
        </template>
        <template #toolbar_buttons>
            <el-radio-group v-model="listQuery.type" size="small" @change="handleSearchList" v-if="type == 1">
              <el-radio-button label="all">全部</el-radio-button>
              <el-radio-button label="send1">距离发货1天</el-radio-button>
              <el-radio-button label="send2">距离发货2-3天</el-radio-button>
              <el-radio-button label="send3">距离发货3天以上</el-radio-button>
              <el-radio-button label="noticeSend">等通知发货</el-radio-button>
              <el-radio-button label="exceedSend">超过发货时间</el-radio-button>
            </el-radio-group>
        </template>
        <template #num1_default="{ row, rowIndex }">
          <el-link @click="toDetail(row)" type="primary"  style="font-size:12px;">{{row.orderSn}}</el-link>
          <div style="color:red" v-if="row.noticeTip != ''">特殊需求：{{row.noticeTip}}</div>
        </template>
        <template #freight_default="{ row, rowIndex }">
            <span>{{row.freightRemark}}</span>

        </template>
        <template #num2_default="{ row, rowIndex }">
          <span>{{row.expectSendDate}}</span>
          <span style="background: red;color:#fff;padding:0 5px;border-radius: 5px" v-if="row.urgentType == '必须'">必须</span>
          <span style="background:#ff6600;color:#fff;padding:0 5px;border-radius: 5px" v-if="row.urgentType == '可延1-2天'">1-2天</span>
          <span style="background:#ff9900;color:#fff;padding:0 5px;border-radius: 5px" v-if="row.urgentType == '可延1-2周'">1-2周</span>
          <span style="background:#0099ff;color:#fff;padding:0 5px;border-radius: 5px" v-if="row.urgentType == '等客户通知'">等待</span>
        </template>
        <template #num3_default="{ row, rowIndex }">
          <span>{{ row.goodsSn }}</span>
          <!-- <el-tooltip class="item" effect="dark" content="Right Center 提示文字" placement="right">
            <img src="../../assets/images/bian.png"  style="vertical-align: middle;"/>
          </el-tooltip> -->
        </template>
        <template #customerName_default="{ row, rowIndex }">
          <div style="white-space: normal;">{{row.customerNumber }}</div>
          <!--是否有权限-->
          <div  style="white-space: normal;">{{row.customerName}}</div>
        </template>

      </vxe-grid>
      <vxe-grid ref='xGrid2' v-bind="gridOptions2" :loading="listLoading2" size="mini" v-else-if="type == 2" >
        <template #form>
          <!--搜索-->
          <div>
            <div style="background: #f5f7fa;padding:15px 15px 0 15px;border:1px solid #EBEEF5;border-bottom:0.5px solid #EBEEF5;">
              <el-form :inline="true" :model="listQuery2" size="mini" label-width="100px">

                  <el-form-item label="期望发货时间：">
                    <el-date-picker
                      :clearable="false"
                      :picker-options="pickerOptions2"
                      v-model="listQuery2.date"
                      type="daterange"
                      format="yyyy 年 MM 月 dd 日"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
                    </el-date-picker>
                  </el-form-item>


                <el-form-item label="客户名称：">
<!--                  <el-input v-model="listQuery2.customerNumber"></el-input>-->
                  <el-select
                    clearable
                    v-model="listQuery2.customerId"
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="querySearch">
                    <el-option
                      v-for="item in querySearchList"
                      :key="item.customerId"
                      :label="item.customerName"
                      :value="item.customerId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="合同号：">
                  <el-input v-model="listQuery2.orderSn"></el-input>
                </el-form-item>
                <el-form-item label="牌号：">
                  <el-input v-model="listQuery2.goodsSn"></el-input>
                </el-form-item>

                <el-form-item label="业务员：">
                  <el-select v-model="listQuery2.orderUserId" filterable placeholder="请选择" clearable >
                    <el-option
                            v-for="item in userOptionList"
                            :key="item.userId"
                            :label="item.realName"
                            :value="item.userId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="提货类型：" >
                  <el-select v-model="listQuery2.sendType"  clearable>
                    <el-option value="运联发货">运联发货</el-option>
                    <el-option value="工厂发货">工厂发货</el-option>
                    <el-option value="客户自提">客户自提</el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="排序：">
                  <el-select v-model="listQuery2.orderBy">
                    <el-option value="default" label="默认更新排序"></el-option>
                    <el-option value="createTime" label="按创建时间排序"></el-option>
                    <el-option value="takeTime" label="提货时间排序"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="排货类型：">
                  <el-select v-model="listQuery2.billType" clearable>
                    <el-option value="saleOrder" label="销售单"></el-option>
                    <el-option value="purchaseOrder" label="采购单"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="合同公司：">
                  <el-input v-model="listQuery2.fromCompany"></el-input>
                </el-form-item>
                <el-form-item label="采购单号：">
                  <el-input v-model="listQuery2.purchaseOrderSn"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button @click="handleSearchList2" type="primary">查询</el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </template>
        <template #pager>
          <div style="overflow: hidden">
            <div class="pagination-container" style="float:right;">
              <el-pagination
                      background
                      @size-change="handleSizeChange2"
                      @current-change="handleCurrentChange2"
                      layout="total, sizes,prev, pager, next,jumper"
                      :current-page.sync="listQuery2.pageNum"
                      :page-size="listQuery2.pageSize"
                      :page-sizes="[10,15,20,50,100,200]"
                      :total="count2">
              </el-pagination>
            </div>
          </div>
        </template>
        <template #toolbar_buttons>
          <el-radio-group size="small" v-model="listQuery2.planState" @change="handleSearchList2">
            <el-radio-button label="">全部</el-radio-button>
            <el-radio-button label="0">待物流发货</el-radio-button>
            <el-radio-button label="10">发货中</el-radio-button>
            <el-radio-button label="25">待提货</el-radio-button>
            <el-radio-button label="30">待出入库</el-radio-button>
            <el-radio-button label="5">已取消</el-radio-button>
          </el-radio-group>
        </template>
        <template #for_default="{ row, rowIndex }">
            <div v-for="(item,index) in row.billGoods" :key="index" v-if="row.billGoods" class="mergeDiv" style="text-align: left" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">
                <span style="vertical-align: middle"><span v-if="item.kingFIndex !=''">{{item.kingFIndex}} / </span>{{item.goodsName}} / {{item.goodsSn}} / {{item.goodsNum}}</span>
                <el-tooltip class="item" effect="dark" :content="item.changeTip" placement="right-end" style="display: inline-block" v-if="item.changeTip != ''">
                  <span style="vertical-align:middle;display: inline-block;background: #409EFF;color: rgb(255, 255, 255);cursor: pointer;padding: 0 2px;line-height: 16px;border-radius: 5px;">变</span>
                </el-tooltip>
            </div>
        </template>
        <template #freight_default="{ row, rowIndex }">
          <div v-for="(item,index) in row.billGoods" :key="index" class="mergeDiv" style="text-align: left" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">
            <span>{{item.freightRemark}}</span>
          </div>
        </template>
        <template #for_default2="{ row, rowIndex }">
          <div v-for="(item,index) in row.billGoods" :key="index" class="mergeDiv" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">{{item.goodsRemark}}</div>
        </template>
        <template #for_default3="{ row, rowIndex }">
          <div>{{row.receiverName}}</div>
          <div>{{row.receiverMobile}}</div>
          <div>{{row.receiveAddress}}</div>
        </template>
        <template #for_default4="{row,rowIndex}">
          <span>{{ row.billSn }} </span>
          <el-tag size="mini" effect="dark" type="danger" v-if="row.isSure==0">不确定</el-tag>
          <el-tag size="mini" effect="dark"  v-if="row.isNeedDriverUnload==1">卸</el-tag>
        </template>

        <template #for_default6="{ row, rowIndex }">
          <div>{{row.driverName}}</div>
          <div>{{row.driverMobile}}</div>
          <div>{{row.driverTruckNo}}</div>
        </template>
        <template #for_default10="{ row, rowIndex }">
          <div>{{row.saleOrderSn}}</div>
          <div style="color:red" v-if="row.noticeTip != ''">特殊需求：{{row.noticeTip}}</div>
        </template>
        <template #for_default7="{row,rowIndex}">
          <el-button type="text" size="small" @click="toInfo(row)" >查看</el-button>
          <!--销售排货--->
          <span v-if="row.billType == 'saleOrder'">
              <el-button type="text" size="small" v-if="row.planState == 30 && row.isNeedCheck==1" @click="showDialogVisible(row)" >确认出库</el-button>
              <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30||row.planState == 40" @click="showPrint(row)">打印单据</el-button>
          </span>

          <!--采购排货--->
          <span v-if="row.billType == 'purchaseOrder'">
              <el-button type="text" size="small" v-if="row.planState == 30" @click="confirmWarehousing(row)">确认入库</el-button>
              <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30||row.planState == 40" @click="showPrint(row)">打印单据</el-button>
          </span>

        </template>
        <template #customerName_default="{ row, rowIndex }">
          <div style="white-space: normal;">{{row.customerNumber }}</div>
          <!--是否有权限-->
          <div  style="white-space: normal;">{{row.customerName}}</div>
        </template>

        <template #for_default8="{ row, rowIndex }">
           <div v-for="(item,index) in row.receivedPicUrl" :key="index" style="color: rgb(64, 158, 255);cursor: pointer;  white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" @click="openUrl(item)">{{item}}</div>
<!--           <el-image v-for="(item,index) in row.receivedPicUrl" :key="index" :src="item" :preview-src-list="row.receivedPicUrl" style="width:50px;height:50px;float: left;margin-right:5px;"></el-image>-->
        </template>

        <template #for_default13="{ row, rowIndex }">
             <div>{{row.sendType}}</div>
             <div>{{row.receiveTips}}</div>
        </template>



      </vxe-grid>
      <vxe-grid ref='xGrid3' v-bind="gridOptions3" :loading="listLoading3" size="mini" v-else-if="type == 3" >
        <template #form>
          <!--搜索-->
          <div>
            <div style="background: #f5f7fa;padding:15px 15px 0 15px;border:1px solid #EBEEF5;border-bottom:0.5px solid #EBEEF5;">
              <el-form :inline="true" :model="listQuery3" size="mini" label-width="100px">
                  <el-form-item label="期望发货时间：">
                    <el-date-picker
                      :clearable="false"
                      :picker-options="pickerOptions2"
                      v-model="listQuery3.date"
                      type="daterange"
                      format="yyyy 年 MM 月 dd 日"
                      value-format="yyyy-MM-dd"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
                    </el-date-picker>
                  </el-form-item>


                <el-form-item label="客户名称：">
                  <el-select
                    clearable
                    v-model="listQuery3.customerId"
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="querySearch">
                    <el-option
                      v-for="item in querySearchList"
                      :key="item.customerName"
                      :label="item.customerName"
                      :value="item.customerId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="合同号：">
                  <el-input v-model="listQuery3.orderSn"></el-input>
                </el-form-item>
                <el-form-item label="牌号：">
                  <el-select
                    clearable
                    v-model="listQuery3.goodsKingId"
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="remoteMethod"
                    :loading="loading">
                    <el-option
                      v-for="item in options"
                      :key="item.kingId"
                      :label="item.goodsSn"
                      :value="item.kingId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="业务员：">
                  <el-select v-model="listQuery3.userId" filterable placeholder="请选择" clearable >
                    <el-option
                      v-for="item in userOptionList"
                      :key="item.userId"
                      :label="item.realName"
                      :value="item.userId">
                    </el-option>
                  </el-select>
                </el-form-item>

                <el-form-item label="发货类型：" >
                  <el-select v-model="listQuery3.sendType"  clearable>
                    <el-option value="公司发货">公司发货</el-option>
                    <el-option value="采购发货">采购发货</el-option>
                    <el-option value="客户自提">客户自提</el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="预计发货仓库：">
                  <el-input v-model="listQuery3.warehouseName" ></el-input>
                </el-form-item>
                <el-form-item label="排序：">
                  <el-select v-model="listQuery3.orderBy">
                    <el-option value="default" label="默认排序"></el-option>
                    <el-option value="checkTime" label="审核时间"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="合同公司：">
                  <el-input v-model="listQuery3.fromCompany" ></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button @click="handleSearchList3" type="primary">查询</el-button>
                </el-form-item>
              </el-form>
            </div>
          </div>
        </template>
        <template #pager>
          <div style="overflow: hidden">
            <div class="pagination-container" style="float:right;">
              <el-pagination
                background
                @size-change="handleSizeChange3"
                @current-change="handleCurrentChange3"
                layout="total, sizes,prev, pager, next,jumper"
                :current-page.sync="listQuery3.pageNum"
                :page-size="listQuery3.pageSize"
                :page-sizes="[10,15,20,50,100,200]"
                :total="count3">
              </el-pagination>
            </div>
          </div>
        </template>

        <template #num1_default="{ row, rowIndex }">
          <el-link @click="toDetail(row)" type="primary"  style="font-size:12px;vertical-align: middle">{{row.orderSn}}</el-link>
          <img src="../../assets/images/yue.png" v-if="row.isTimeSure == 1" style="vertical-align: middle;"/>
          <img src="https://pic.moresu.com/FseQ3_RZIxs7oqxHV_58E4pIbY8n" v-if="row.isSure==1" style="width:16px;vertical-align: middle">
          <img src="https://pic.moresu.com/FoTOVVQAuxPqFyvhBWdO-tQXyeEY" v-if="row.isSure==0" style="width:20px;vertical-align: middle">
          <img src="https://pic.moresu.com/FhIaQcrC8Mbtqn9EmG4uteNBibd7" v-if="row.activityType == 'paiMai'"  style="vertical-align: middle;width:16px"/>
        </template>
        <template #customerName_default="{ row, rowIndex }">
          <div style="white-space: normal;">{{row.customerNumber }}</div>
          <!--是否有权限-->
          <div  style="white-space: normal;">{{row.customerName}}</div>
        </template>
      </vxe-grid>
    </div>

    <warehouse v-if="tab == 'warehouse'"></warehouse>


    <!--提货信息弹窗-->
    <arrangeDelivery ref="arrangeDelivery" @getList="getList"></arrangeDelivery>

    <!--自提信息弹窗-->
    <selfMention ref="selfMention" @getList="getList"></selfMention>

    <!--合并排货-->
    <mergeDelivery ref="mergeDelivery" @handleConfirmMerge="handleConfirmMerge"></mergeDelivery>

    <!--采购排货-->
    <pumsDelivery ref="pumsDelivery" @handleConfirmPums="handleConfirmPums"></pumsDelivery>

    <!--详情-->
    <el-drawer
            size="1000px"
            :modal="false"
            title="排货详情"
            :visible.sync="drawer"
            direction="rtl">
      <dischargingInfo ref="dischargingInfo"  userType="pums"
                       @showCancelForm="showCancelForm"
                       @showPrint="showPrint"
                       @showDialogVisible="showDialogVisible"
                       @confirmWarehousing="confirmWarehousing"
                       @showDialogVisible4="showDialogVisible4"
                       @refresh="refresh"
      ></dischargingInfo>
    </el-drawer>

    <!--打印弹窗-->
    <printdischarging ref="printdischarging" @update="getList2"></printdischarging>

    <!--确认出库-->
    <confirmOut ref="confirmOut" @refresh="refresh"></confirmOut>

    <!--取消排货-->
    <cancelShipment ref="cancelShipment" @refresh="refresh"></cancelShipment>

    <!--修改司机信息-->
    <logisticsConfirmsDelivery ref="logisticsConfirmsDelivery" @refresh="refresh"></logisticsConfirmsDelivery>

    <!--显示标记-->
    <el-dialog
      title="标记"
      :visible.sync="dialogVisiblebj"
      width="500px">
      <div style="max-height: 500px;overflow: auto">
        <el-form size="mini" label-width="100px" ref="formbj" :model="formbj" :rules="rulesbj">
          <el-form-item label="标记类型：" prop="tagContent">
            <el-radio-group v-model="formbj.tagContent" @input="changeTagContent">
              <el-radio style="margin:8px 6px;" v-for="(item,index) in tagContentList" :key="index" :label="item"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="标记内容：" v-if="formbj.tagContent=='自定义'">
            <el-input v-model="zdjTagContent" clearable style="width: 300px;"></el-input>
          </el-form-item>
          <el-form-item label="日期：" v-if="formbj.tagContent!='取消标记'">
            <el-date-picker
              v-model="tagContentTime"
              align="right"
              type="date"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: right">
          <el-button @click="dialogVisiblebj = false" size="small">取 消</el-button>
          <el-button type="primary" @click="handleConfirmbj" :loading="btnLoadingbj" size="small">确 定</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {goodsList} from '@/api/company'
import {getUserOption,getCustomerOption,getGoodsClassList,getConfigList} from '@/api/partner'
import {planOrderGoodsList,planGoodsListScheduled,checkStockIn,directDeliverGoods,checkGoodsPlan,editTagContent} from '@/api/order'
import {formatDate} from '@/utils/date';
import store from '@/store'
import arrangeDelivery from './components/arrangeDelivery.vue'
import selfMention from './components/selfMention.vue'
import mergeDelivery from './components/mergeDelivery.vue'
import pumsDelivery from './components/pumsDelivery.vue'
import warehouse from './components/warehouse.vue'
import { mapGetters } from 'vuex'
import dischargingInfo from '@/views/components/dischargingInfo'
import printdischarging from '@/views/components/printdischarging'
import confirmOut from '@/views/components/confirmOut'
import cancelShipment from '@/views/components/cancelShipment'
import logisticsConfirmsDelivery from '@/views/components/logisticsConfirmsDelivery'
const defaultListQuery={
  pageNum: 1,
  pageSize: 10,
  date : [], //希望发货日期
  sendType : "", //发货类型(公司发货、采购发货、客户自提)
  warehouseName : "", //预计发货仓库
  orderSn : "", //合同单号
  customerId : '', //客户ID
  userId : '', //业务员ID
  financeState : 0, //财务审核状态(0-未审核，1-已审核，2-已关闭)
  goodsName : "", //品名
  goodsKingId : "", //指定牌号
  planDeliverState : '', //排货状态(0未安排，1部分安排, 2已安排)
  orderBy:'financeTimeDesc',
  tab:'my',
  goodsKingName:'',
  fromCompany:'',
  purchaseOrderSn:'',
  customerNumber:'',
  tagContent: [],
  isFilterBrand:'',
  type:'all',
  brandName:''
};
const defaultListQuery2 = {
  tab:'my',
  pageNum: 1,
  pageSize: 10,
  planState   : '',       //排货状态(0已排货，5已取消,10发货中，20待安排司机 30待出库 40已出库)
  "date"        : [], //提货日期
  "orderSn"     : "", //合同号
  "goodsKingId" : '', //商品SAPID
  "customerId"  : '',  //客户ID
  "orderUserId" : '', //业务员ID
  "sendType"    : "", //提货类型('运联发货','工厂发货','客户自提')
  "purchaseOrderSn" : "", //采购单号
  "planUserId"  : '',  //创建人
  "billType"    : "", //排货类型(采购单-purchaseOrder,代加工单-agentProcess,销售单-saleOrder)
  "orderBy"     : "default", //排序(createTime-按创建时间排序，takeTime-按提货时间排序)
  goodsSn:'',
  fromCompany:'',
  customerNumber:''

};

const defaultListQuery3 = {
  tab:'my',
  pageNum: 1,
  pageSize: 10,
  "date"  : [],   //希望发货时间
  "customerId" :  '', //客户ID
  "orderSn" : "", //合同号
  "goodsKingId" : '', //商品SAPID
  "userId" : '', //业务员ID
  "sendType" : "", //发货类型
  "warehouseName" : "", //预计发货仓库
  "orderBy" : "" ,//排序(按审核时间-checkTime,默认排序-"")
  fromCompany:'',
  customerNumber:''
};

const defaultFormbj = {
  orderId:'',
  tagContent:''
}

export default {
  name: "index",
  components: {
    arrangeDelivery: arrangeDelivery,
    selfMention: selfMention,
    mergeDelivery: mergeDelivery,
    pumsDelivery: pumsDelivery,
    dischargingInfo: dischargingInfo,
    printdischarging: printdischarging,
    confirmOut: confirmOut,
    cancelShipment: cancelShipment,
    logisticsConfirmsDelivery: logisticsConfirmsDelivery,
    warehouse
  },
  data() {
    return {
      type: '1',
      tab: 'my',
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData: [],
      count: 0,
      listLoading: false,
      customerStateList: [],
      userOptionList: [],
      options: [],
      loading: false,
      roles: store.getters.roles ? store.getters.roles : [],
      loading2: false,
      ogId: '',
      loading4: false,
      querySearchList: [],
      unPlanNum: '',
      hasPlanNum: '',
      gridOptions: {
        loading: this.listLoading,
        border: true,
        id: 'full_edit_2',
        align: 'center',
        autoResize: true,
        height: 800,
        size: 'mini',
        rowConfig: {
          keyField: 'ogId',
          isHover: true
        },
        columnConfig: {
          resizable: true
        },
        customConfig: {
          storage: true,
        },
        checkboxConfig: {
          reserve: true
        },
        toolbarConfig: {
          zoom: true,
          custom: true,
          slots: {
            buttons: 'toolbar_buttons',
          }
        },
        spanMethod({ row, rowIndex, $rowIndex, _rowIndex, column, columnIndex, $columnIndex, _columnIndex, visibleData }) {
          let fields = ['orderSn', 'createTime', 'customerName', 'userRealName', 'timeSureDate', 'financeTime']
          if (!fields.includes(column['field'])) {
            return { rowspan: 1, colspan: 1 }
          } else if (row['isMerge'] && (fields.includes(column['field']))) {
            return { rowspan: row['rowNum'], colspan: 1 }
          } else {
            return { rowspan: 0, colspan: 0 }
          }

        },
        columns: [
          {
            type: 'checkbox',
            title: '',
            fixed: 'left',
            width: 50,
          },
          {
            field: 'orderSn',
            title: '合同号',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'num1_default',
            }
          },
          {
            field: 'freightRemark',
            title: '询盘备注',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'freight_default',
            }
          },
          {
            field: 'createTime',
            title: '订单时间',
            width: 100,
          },
          {
            field: 'planDeliverState',
            title: '安排状态',
            width: 100,
            formatter({ cellValue }) {
              if (cellValue == 0) {
                return '未安排'
              } else if (cellValue == 1) {
                return '部分安排'
              } else if (cellValue == 2) {
                return '已安排'
              }
            }
          },
          {
            field: 'tagContent',
            title: '标记',
            width: 180,
          },
          {
            field: 'expectSendDate',
            title: '期望发货时间',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'num2_default',
            }
          },
          {
            field: 'sendDate',
            title: '预计发货时间',
            width: 150,
          },
          {
            field: 'timeSureDate',
            title: '合同约定时间',
            width: 150,
          },
          {
            field: 'financeTime',
            title: '财务审核时间',
            width: 150,
          },
          {
            field: 'customerName',
            title: '客户名称',
            width: 200,
            slots: {
              default: 'customerName_default'
            }
          },
          {
            field: 'fromCompany',
            title: '合同公司',
            width: 100,
          },
          {
            field: 'userRealName',
            title: '业务员',
            width: 100,
          },
          {
            field: 'goodsSn',
            title: '商品信息',
            width: 150,
            slots: {
              default: 'num3_default'
            }
          },
          {
            field: 'goodsPrice',
            title: '合同单价',
            width: 100,
          },
          {
            field: 'goodsNum',
            title: '合同数量',
            width: 100,
          },
          {
            field: 'unSendNum',
            title: '未发货数量',
            width: 100,
            showOverflow: true,
          },
          {
            field: 'planNum',
            title: '已安排数量',
            width: 100,
            showOverflow: true,
          },
          {
            field: 'goodsAmount',
            title: '合同金额',
            width: 100,
          },
          {
            field: 'deliveryType',
            title: '物流方式',
            width: 150,
          },

          {
            field: 'warehouseName',
            title: '预计发货仓库',
            width: 150,
          },
          {
            field: 'sendType',
            title: '发货类型',
            width: 100,
            fixed: 'right'
          },
          {
            field: 'goodsRemark',
            title: '商品备注',
            width: 150,
            fixed: 'right'
          },
          {
            field: '',
            title: '操作',
            width: 150,
            fixed: 'right',
            slots: {
              // 使用 JSX 渲染
              default: ({ row }) => {
                if(this.type == 1){
                  return [
                    <el-button style="margin-right:10px;" type="text" size="small" onClick={() => this.showDialog3(row)}>安排提货</el-button>,
                    <el-button style="margin-right:10px;" type="text" size="small" onClick={() => this.showBiaobi(row)}>标记</el-button>,
                    // <el-button v-if="row.sendType=='客户自提'" style="margin-left:0" type="text" size="small" onClick={ () =>this.showDialog4(row) }>自提信息 </el-button>
                  ]
                }else if(this.type == 4){
                  return [
                    <span>订单待审核</span>
                    ]
                }
              }
            },
          },
        ],
        data: [],
      },
      pickerOptions2: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '明天',
          onClick(picker) {
            let date = new Date();
            let startTime = date.setTime(date.getTime() + 3600 * 1000 * 24);
            let startDate = formatDate(new Date(startTime), 'yyyy-MM-dd')
            picker.$emit('pick', [startDate, startDate]);
          }
        }, {
          text: '本月',
          onClick(picker) {
            let now = new Date();
            let nowMonth = now.getMonth(); //当前月
            let nowYear = now.getFullYear(); //当前年
            //本月的开始时间
            let monthStartDate = new Date(nowYear, nowMonth, 1);
            //本月的结束时间
            let monthEndDate = new Date(nowYear, nowMonth + 1, 0, 23, 59, 59);
            let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
            let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
            picker.$emit('pick', [startDate, endDate]);
          }
        }, {
          text: '上个月',
          onClick(picker) {
            let now = new Date();
            let nowMonth = now.getMonth(); //当前月
            let nowYear = now.getFullYear(); //当前年
            console.log("nowMonth", nowMonth)
            if (nowMonth == 0) {   //如果是0，则说明是1月份，上一个月就是去年的12月
              nowYear -= 1;
              nowMonth = 11;
            } else {
              nowMonth = nowMonth - 1
            }
            //上月的开始时间
            let monthStartDate = new Date(nowYear, nowMonth, 1);
            //上月的结束时间
            let monthEndDate = new Date(nowYear, nowMonth + 1, 0, 23, 59, 59);
            let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
            let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
            picker.$emit('pick', [startDate, endDate]);
          },
        }, {
          text: '三个月',
          onClick(picker) {
            let date = new Date();
            let endDate = formatDate(new Date(), 'yyyy-MM-dd');
            let startTime = date.setTime(date.getTime() - 3600 * 1000 * 24 * 90);
            let startDate = formatDate(new Date(startTime), 'yyyy-MM-dd')
            picker.$emit('pick', [startDate, endDate]);
          },
        }, {
          text: '六个月',
          onClick(picker) {
            let date = new Date();
            let endDate = formatDate(new Date(), 'yyyy-MM-dd');
            let startTime = date.setTime(date.getTime() - 3600 * 1000 * 24 * 180);
            let startDate = formatDate(new Date(startTime), 'yyyy-MM-dd')
            picker.$emit('pick', [startDate, endDate]);
          },
        }]
      },
      records: [],
      gridOptions2: {
        border: true,
        id: 'full_edit_3',
        align: 'center',
        height: 800,
        rowConfig: {
          keyField: 'billId',
          isHover: true
        },
        columnConfig: {
          resizable: true
        },
        customConfig: {
          storage: true,
        },
        toolbarConfig: {
          zoom: true,
          custom: true,
          slots: {
            buttons: 'toolbar_buttons',
          }
        },
        columns: [

          {
            field: 'billSn',
            title: '编号',
            width: 150,
            slots: {
              default: 'for_default4',
            },

          },
          {
            field: 'freightRemark',
            title: '询盘备注',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'freight_default',
            }
          },
          {
            field: 'erpOrderSn',
            title: '金蝶排货单号',
            width: 150,
          },
          {
            field: 'billType',
            title: '排货类型',
            width: 100,
            formatter({ cellValue }) {
              if (cellValue == 'purchaseOrder') {
                return '采购单'
              } else if (cellValue == 'saleOrder') {
                return '销售单'
              } else if (cellValue == 'agentProcess') {
                return '代加工单'
              }
            }
          },
          {
            field: 'saleOrderSn',
            title: '销售订单号',
            width: 150,
            slots: {
              default: 'for_default10',
            },
          },
          {
            field: 'customerName',
            title: '客户名称',
            width: 200,
            slots: {
              default: 'customerName_default'
            }
          },
          {
            field: 'fromCompany',
            title: '合同公司',
            width: 100,
          },
          {
            field: 'pbgId',
            title: '商品信息',
            width: 200,
            className: 'mergeCell',
            slots: {
              // 使用插槽模板渲染
              default: 'for_default',
            }
          },
          {
            field: 'goodsRemark',
            title: '商品备注',
            className: 'mergeCell',
            width: 100,
            slots: {
              // 使用插槽模板渲染
              default: 'for_default2',
            }
          },
          {
            field: 'receiveAddress',
            title: '收货信息',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'for_default3',
            }
          },
          {
            field: 'billTakeNum',
            title: '提货数量',
            width: 100,
            formatter({ cellValue }) {
              return cellValue + '吨'
            }
          },
          {
            field: 'takeWarehouse',
            title: '提货仓库',
            width: 150,
          },
          {
            field: 'takeAddress',
            title: '提货地址',
            width: 150,
          },
          {
            field: 'takeTime',
            title: '提货时间',
            width: 150,
          },
          {
            field: 'sendType',
            title: '提货类型',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'for_default13',
            }
          },
          {
            field: 'takeRemark',
            title: '提货备注',
            width: 150,
            showOverflow: true,
          },
          {
            field: 'warehouseRemark',
            title: '仓库备注',
            width: 150,
            showOverflow: true,
          },
          {
            field: 'purchaseOrderSn',
            title: '采购合同号',
            width: 150,
          },
          {
            field: 'userRealName',
            title: '业务员',
            width: 100,
          },
          {
            field: 'driverName',
            title: '司机信息',
            width: 150,
            slots: {
              // 使用插槽模板渲染
              default: 'for_default6',
            }
          },
          {
            field: 'deliverSn',
            title: '发货单号',
            width: 150,
          },
          {
            field: 'planState',
            title: '排货状态',
            width: 100,
            formatter({ cellValue }) {
              if (cellValue == 0) {
                return '待物流发货'
              } else if (cellValue == 5) {
                return '已取消'
              } else if (cellValue == 10) {
                return '发货中'
              } else if (cellValue == 20) {
                return '待安排司机'
              } else if (cellValue == 25) {
                return '待提货'
              } else if (cellValue == 30) {
                return '待出库'
              } else if (cellValue == 40) {
                return '已出库'
              }
            }
          },
          {
            field: 'createdTime',
            title: '创建时间',
            width: 150,
          },
          {
            field: 'createdUser',
            title: '创建人',
            width: 100
          },
          {
            field: 'logisticsUserName',
            title: '物流调度',
            width: 100,
          },
          {
            field: 'updatedTime',
            title: '更新时间',
            width: 150,
          },
          {
            field: 'cancelType',
            title: '取消类型',
            width: 100,
          },
          {
            field: 'cancelReason',
            title: '取消原因',
            width: 150,
          }, {
            field: 'lossFreight',
            title: '运费损失',
            width: 100,
          },
          {
            field: '',
            title: '收货确认函',
            width: 100,
            fixed: 'right',
            slots: {
              default: 'for_default8',
            },

          },
          {
            field: '',
            title: '操作',
            width: 100,
            fixed: 'right',
            slots: {
              default: 'for_default7',
            },

          },
        ],
        data: [],
      },
      listLoading2: false,
      count2: 0,
      listQuery2: JSON.parse(JSON.stringify(defaultListQuery2)),
      drawer: false,
      gridOptions3: {
        loading: this.listLoading3,
        border: true,
        id: 'full_edit_4',
        align: 'center',
        height: 800,
        autoResize: true,
        rowConfig: {
          keyField: 'ogId',
          isHover: true
        },
        columnConfig: {
          resizable: true
        },
        customConfig: {
          storage: true,
        },
        checkboxConfig: {
          reserve: true
        },
        toolbarConfig: {
          zoom: true,
          custom: true,
        },
        columns: [
          {
            field: 'orderSn',
            title: '合同号',
            width: 150,
          },
          {
            field: 'orderTime',
            title: '订单时间',
            width: 100,
          },
          {
            field: 'expectSendDate',
            title: '期望发货时间',
            width: 150,
          },
          {
            field: 'timeSureDate',
            title: '合同约定时间',
            width: 150,
          },
          {
            field: 'financeTime',
            title: '财务审核时间',
            width: 150,
          },
          {
            field: 'customerName',
            title: '客户名称',
            width: 200,
            slots: {
              default: 'customerName_default'
            }
          },
          {
            field: 'userName',
            title: '业务员',
            width: 100,
          },
          {
            field: 'planState',
            title: '安排状态',
            width: 100,
            formatter({ cellValue }) {
              if (cellValue == 0) {
                return '待物流发货'
              } else if (cellValue == 5) {
                return '已取消'
              } else if (cellValue == 10) {
                return '发货中'
              } else if (cellValue == 20) {
                return '待安排司机'
              } else if (cellValue == 25) {
                return '待提货'
              } else if (cellValue == 30) {
                return '待出库'
              } else if (cellValue == 40) {
                return '已出库'
              }
            }
          },
          {
            field: 'goodsName',
            title: '商品信息',
            width: 150,
            slots: {
              // 使用 JSX 渲染
              default: ({ row }) => {
                return [
                  row.goodsName + '/' + row.goodsSn
                ]
              }
            },
          },
          {
            field: 'goodsPrice',
            title: '合同单价',
            width: 100,
          },
          {
            field: 'goodsNum',
            title: '合同数量',
            width: 100,
          },
          {
            field: 'unSendNum',
            title: '未发货数量',
            width: 100,
            showOverflow: true,
          },
          {
            field: 'goodsPlanNum',
            title: '已安排数量',
            width: 100,
            showOverflow: true,
          },
          {
            field: 'goodsAmount',
            title: '合同金额',
            width: 100,
          },
          {
            field: 'deliveryType',
            title: '交易方式',
            width: 150,
          },
          {
            field: 'sendDate1',
            title: '预计发货时间',
            width: 150,
          },
          {
            field: 'warehouseName',
            title: '预计发货仓库',
            width: 150,
          },
          {
            field: 'sendType',
            title: '发货类型',
            width: 100,
          },
          {
            field: 'goodsRemark',
            title: '备注',
            width: 150,
          },
          {
            field: '',
            title: '操作',
            width: 100,
            fixed: 'right',
            slots: {
              // 使用 JSX 渲染
              default: ({ row }) => {
                return [
                  <el-button style="margin-left:0" type="text" size="mini" onClick={() => this.confirmArrange(row)}>确认安排</el-button>,
                ]
              }
            },
          },
        ],
        data: [],
      },
      listLoading3: false,
      count3: 0,
      listQuery3: JSON.parse(JSON.stringify(defaultListQuery3)),
      options2: [],
      dialogVisiblebj: false,
      formbj: JSON.parse(JSON.stringify(defaultFormbj)),
      tagContentList:['不紧急','延迟排货','短期不排货','自定义','取消标记','空白'],
      tagContentTime: '',
      zdjTagContent: '',
      btnLoadingbj: false,
      rulesbj: {
        tagContent: [{ required: true, message: '此项必填', trigger: 'change' },],
      },
      goodsTabList:[]
    }
  },
  created() {
    if(this.$route.query.planState){
      this.listQuery2.planState = this.$route.query.planState
    }
    if(this.$route.query.type){
        this.type = this.$route.query.type
        this.changeType(this.type)
    }
    let now = new Date();
    let nowMonth = now.getMonth(); //当前月
    let nowYear = now.getFullYear(); //当前年
    let nowMonth2 = now.getMonth();
    let nowYear2 = now.getFullYear();
    if (nowMonth2 == 0) {   //如果是0，则说明是1月份，上一个月就是去年的12月
      nowYear2 -= 1;
      nowMonth2 = 11;
    } else {
      nowMonth2 = nowMonth2 - 1
    }
    //上月的开始时间
    let monthStartDate = new Date(nowYear2, nowMonth2, 1);
    console.log("monthStartDate", monthStartDate)
    //本月的结束时间
    let monthEndDate = new Date(nowYear, nowMonth + 1, 0, 23, 59, 59);
    let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
    let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
    this.listQuery.date = [startDate, endDate];
    this.listQuery2.date = [startDate, endDate];
    this.listQuery3.date = [startDate, endDate];
    this.getList();
    this.getUserOptionList();
    this.remoteMethod3()
    this.getGoodsTabList()
  },
  filters: {
    formatCreateTime(time) {
      if (time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      } else {
        return '--'
      }
    },
    fifterState(val) {
      if (val == 0) {
        return '未安排'
      } else if (val == 1) {
        return '部分安排'
      } else if (val == 2) {
        return '已安排'
      }
    },
  },
  methods: {
    getGoodsTabList(){
      getConfigList().then((res)=>{
        let GoodsTab = res.find((el)=>{
          return  el.cdtCode == 'plan_brand_name'
        })
        this.goodsTabList = GoodsTab ? GoodsTab.data : []
      })
    },
    openUrl(item){
      window.open(item)
    },
    changeTagContent(val) {
      this.tagContentTime = '';
      this.zdjTagContent = '';
    },
    //显示标记
    showBiaobi(item) {
      this.formbj.orderId = item.orderId;
      this.formbj.tagContent = '';
      this.tagContentTime = '';
      this.zdjTagContent = '';
      this.dialogVisiblebj = true;
    },

    handleConfirmbj() {
      this.$refs.formbj.validate((valid) => {
        if (valid) {
          this.btnLoadingbj = true;
          const data = JSON.parse(JSON.stringify(this.formbj));
          if (this.zdjTagContent!=''||this.tagContentTime!=''){
            // data.tagContent = data.tagContent + '\n' + (this.zdjTagContent ? this.zdjTagContent + '\n' : '') + this.tagContentTime;
            data.tagContent = `${data.tagContent}\n${this.zdjTagContent ? this.zdjTagContent + '\n' : ''}${this.tagContentTime}`;
          }else if(data.tagContent == '取消标记') {
            data.tagContent = '';
          }
          editTagContent(data).then(() => {
            this.btnLoadingbj = false;
            this.dialogVisiblebj = false
            this.getList()
          }).catch(() => {
            this.btnLoadingbj = false;
          })
        }
      })
    },

    //获取品类列表
    remoteMethod3() {
      getGoodsClassList().then((res) => {
        this.options2 = res;
      }).catch(() => {
      });
    },
    changeType(key) {
      if (key == 1 || key == 4) {
        this.listQuery.type = 'all'
        this.handleSearchList()
      } else if (key == 2) {
        this.handleSearchList2()
      } else if (key == 3) {
        this.handleSearchList3()
      }
    },
    changeTab(key) {
      this.tab = key;
      if (key != 'warehouse') {
        this.listQuery.tab = key;
        this.listQuery2.tab = key;
        this.listQuery3.tab = key;
        this.changeType(this.type)
      }
    },

    //确认安排
    confirmArrange(item) {
      this.$confirm('确认将此记录设置为已安排?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        checkGoodsPlan({ ogId: item.ogId }).then(() => {
          this.getList3()
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },

    //刷新页面
    refresh(billId) {
      this.getList2();
      if (this.drawer) {
        this.$refs.dischargingInfo.init(billId)
      }
    },
    //打开详情
    toInfo(item) {
      this.drawer = true;
      setTimeout(() => {
        this.$refs.dischargingInfo.init(item.billId)
      }, 300)
    },

    //显示确认出库
    showDialogVisible(item) {
      this.$refs.confirmOut.showDialogVisible(item);
    },

    //显示打印
    showPrint(item, checked) {
      this.$refs.printdischarging.showPrint(item.billId, checked);
    },

    //显示取消排货
    showCancelForm(billId) {
      this.$refs.cancelShipment.showCancelForm(billId)
    },
    //确认入库
    confirmWarehousing(item) {
      this.$confirm('确认将此记录变成已入库?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        checkStockIn({ billId: item.billId }).then(() => {
          this.refresh(item.billId)
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        });
      });
    },

    //显示修改司机信息
    showDialogVisible4(item, title) {
      this.$refs.logisticsConfirmsDelivery.showDialogVisible4(item, title,'pums');
    },

    //采购排货
    pumsph() {
      this.$refs.pumsDelivery.showDialog2()
    },
    //提交采购排货
    handleConfirmPums() {

    },

    //合并排货
    margeph() {
      let list = this.$refs.xGrid.getCheckboxReserveRecords();
      let list2 = this.$refs.xGrid.getCheckboxRecords();
      this.records = JSON.parse(JSON.stringify(list.concat(list2)));
      console.log("records", this.records)
      if (this.records.length == 0) {
        this.$message({
          type: 'info',
          message: '请先选择记录！'
        });
        return false
      }
      this.$refs.mergeDelivery.showDialog2(this.records)
    },
    //提交合并排货
    handleConfirmMerge() {
      this.$refs.xGrid.clearCheckboxRow(false);
      this.$refs.xGrid.clearCheckboxReserve()
      this.getList()
    },
    showDialog3(item) {
      this.$refs.arrangeDelivery.showDialog3(item)
    },
    checkboxChange(checked) {
      this.records = JSON.parse(JSON.stringify(checked.records));
    },

    showDialog4(item) {
      this.$refs.selfMention.showDialog4(item)
    },



    //获取员工下拉选项
    getUserOptionList() {
      getUserOption().then((res) => {
        this.userOptionList = res;
      })
    },

    //客户名称输入匹配
    querySearch(queryString) {
      getCustomerOption({ keywords: queryString }).then((res) => {
        this.querySearchList = res;
      })
    },


    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        goodsList({ keywords: query }).then((res) => {
          this.options = res.list;
          this.loading = false;
        })
      } else {
        this.options = [];
        this.loading = false;
      }
    },



    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.$refs.xGrid.clearCheckboxRow(false);
      this.$refs.xGrid.clearCheckboxReserve()
      this.getList();
    },


    //获取需排货列表
    getList() {
      this.listLoading = true;
      let data = JSON.parse(JSON.stringify(this.listQuery))
      data.tagContent=data.tagContent.join(',')
      if(this.type == 4){
        data.type='depositOrder'
      }
      planOrderGoodsList(data).then(response => {
        this.gridOptions.data = [];
        response.list.forEach((el, i) => {
          let newEL = JSON.parse(JSON.stringify(el));
          delete newEL.ordGoodsList
          el.ordGoodsList.forEach((ee, ii) => {
            let newEE = JSON.parse(JSON.stringify(ee));
            if (ii == 0) {
              // console.log("ii", ii)
              newEE.isMerge = true;
              newEE.rowNum = el.ordGoodsList.length;
            } else {
              newEE.isMerge = false;
              newEE.rowNum = 0;
            }
            let copy = Object.assign({}, newEL, newEE);
            this.gridOptions.data.push(copy);
          })
        })
        this.count = response.count;
        this.unPlanNum = response.unPlanNum ? response.unPlanNum : '';
        this.listLoading = false;
      }).catch(() => {
        this.listLoading = false;
      });
    },

    //去详情页
    toDetail(item) {
      let routeData = this.$router.resolve({ name: 'purchaseDetail', query: { id: item.orderId, type: 'see' } });
      window.open(routeData.href);
    },


    handleSizeChange2(val) {
      this.listQuery2.pageNum = 1;
      this.listQuery2.pageSize = val;
      this.getList2();
    },
    handleCurrentChange2(val) {
      this.listQuery2.pageNum = val;
      this.getList2();
    },

    handleSearchList2() {
      this.listQuery2.pageNum = 1;
      this.getList2();
    },

    //获取已排货列表
    getList2() {
      this.listLoading2 = true;
      planGoodsListScheduled(this.listQuery2).then(response => {
        this.gridOptions2.data = response.list;
        this.count2 = response.count;
        this.listLoading2 = false;
      }).catch(() => {
        this.listLoading2 = false;
      });
    },



    handleSizeChange3(val) {
      this.listQuery3.pageNum = 1;
      this.listQuery3.pageSize = val;
      this.getList3();
    },
    handleCurrentChange3(val) {
      this.listQuery3.pageNum = val;
      this.getList3();
    },

    handleSearchList3() {
      this.listQuery3.pageNum = 1;
      this.getList3();
    },

    //获取未安排已发货列表
    getList3() {
      this.listLoading3 = true;
      directDeliverGoods(this.listQuery3).then(response => {
        this.gridOptions3.data = response.list;
        this.count3 = response.count;
        this.listLoading3 = false;
      }).catch(() => {
        this.listLoading3 = false;
      });
    },

  },
};
</script>

<style lang="scss">
.mergeDiv{
  border-bottom:1px solid #e8eaec;
  min-height: 36px;
  padding-left:10px;
  padding-right:10px;
}

.mergeDiv:last-child{
  border-bottom: 0;
}

.mergeCell .vxe-cell{padding:0;}



</style>
